home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / spy.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  12KB  |  390 lines

  1. /***************************************************************************
  2.  
  3. S.P.Y. (c) 1989 Konami
  4.  
  5. Similar to Bottom of the Ninth
  6.  
  7. driver by Nicola Salmoria
  8.  
  9. ***************************************************************************/
  10.  
  11. #include "driver.h"
  12. #include "vidhrdw/generic.h"
  13. #include "cpu/m6809/m6809.h"
  14. #include "vidhrdw/konamiic.h"
  15.  
  16.  
  17. int spy_vh_start(void);
  18. void spy_vh_stop(void);
  19. void spy_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  20.  
  21.  
  22.  
  23. static int spy_interrupt(void)
  24. {
  25.     if (K052109_is_IRQ_enabled())
  26.     {
  27.         if (cpu_getiloops()) return M6809_INT_FIRQ;    /* ??? */
  28.         else return interrupt();
  29.     }
  30.     else return ignore_interrupt();
  31. }
  32.  
  33.  
  34. static int rambank;
  35. static unsigned char *ram;
  36.  
  37. static READ_HANDLER( spy_bankedram1_r )
  38. {
  39.     if (!rambank) return ram[offset];
  40.     else return paletteram_r(offset);
  41. }
  42.  
  43. static WRITE_HANDLER( spy_bankedram1_w )
  44. {
  45.     if (!rambank) ram[offset] = data;
  46.     else paletteram_xBBBBBGGGGGRRRRR_swap_w(offset,data);
  47. }
  48.  
  49. static WRITE_HANDLER( bankswitch_w )
  50. {
  51.     unsigned char *rom = memory_region(REGION_CPU1);
  52.     int offs;
  53.  
  54.     /* bit 0 = RAM bank? */
  55. if ((data & 1) == 0) usrintf_showmessage("bankswitch RAM bank 0");
  56.  
  57.     /* bit 1-4 = ROM bank */
  58.     if (data & 0x10) offs = 0x20000 + (data & 0x06) * 0x1000;
  59.     else offs = 0x10000 + (data & 0x0e) * 0x1000;
  60.     cpu_setbank(1,&rom[offs]);
  61. }
  62.  
  63. static WRITE_HANDLER( spy_3f90_w )
  64. {
  65.     /* bits 0/1 = coin counters */
  66.     coin_counter_w(0,data & 0x01);
  67.     coin_counter_w(1,data & 0x02);
  68.  
  69.     /* bit 2 = enable char ROM reading through the video RAM */
  70.     K052109_set_RMRD_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
  71.  
  72.     /* bit 4 = select RAM at 0000 */
  73.     rambank = data & 0x10;
  74.  
  75.     /* other bits unknown */
  76. }
  77.  
  78.  
  79. static WRITE_HANDLER( spy_sh_irqtrigger_w )
  80. {
  81.     cpu_cause_interrupt(1,0xff);
  82. }
  83.  
  84. static WRITE_HANDLER( sound_bank_w )
  85. {
  86.     unsigned char *rom;
  87.     int bank_A,bank_B;
  88.  
  89.     rom = memory_region(REGION_SOUND1);
  90.     bank_A = 0x20000 * ((data >> 0) & 0x03);
  91.     bank_B = 0x20000 * ((data >> 2) & 0x03);
  92.     K007232_bankswitch(0,rom + bank_A,rom + bank_B);
  93.     rom = memory_region(REGION_SOUND2);
  94.     bank_A = 0x20000 * ((data >> 4) & 0x03);
  95.     bank_B = 0x20000 * ((data >> 6) & 0x03);
  96.     K007232_bankswitch(1,rom + bank_A,rom + bank_B);
  97. }
  98.  
  99.  
  100.  
  101. static struct MemoryReadAddress spy_readmem[] =
  102. {
  103.     { 0x0000, 0x07ff, spy_bankedram1_r },
  104.     { 0x0800, 0x1aff, MRA_RAM },
  105.     { 0x3fd0, 0x3fd0, input_port_4_r },
  106.     { 0x3fd1, 0x3fd1, input_port_0_r },
  107.     { 0x3fd2, 0x3fd2, input_port_1_r },
  108.     { 0x3fd3, 0x3fd3, input_port_2_r },
  109.     { 0x3fe0, 0x3fe0, input_port_3_r },
  110.     { 0x2000, 0x5fff, K052109_051960_r },
  111.     { 0x6000, 0x7fff, MRA_BANK1 },
  112.     { 0x8000, 0xffff, MRA_ROM },
  113.     { -1 }    /* end of table */
  114. };
  115.  
  116. static struct MemoryWriteAddress spy_writemem[] =
  117. {
  118.     { 0x0000, 0x07ff, spy_bankedram1_w, &ram },
  119.     { 0x0800, 0x1aff, MWA_RAM },
  120.     { 0x3f80, 0x3f80, bankswitch_w },
  121.     { 0x3f90, 0x3f90, spy_3f90_w },
  122.     { 0x3fa0, 0x3fa0, watchdog_reset_w },
  123.     { 0x3fb0, 0x3fb0, soundlatch_w },
  124.     { 0x3fc0, 0x3fc0, spy_sh_irqtrigger_w },
  125.     { 0x2000, 0x5fff, K052109_051960_w },
  126.     { 0x6000, 0x7fff, MWA_ROM },
  127.     { 0x8000, 0xffff, MWA_ROM },
  128.     { -1 }    /* end of table */
  129. };
  130.  
  131. static struct MemoryReadAddress spy_sound_readmem[] =
  132. {
  133.     { 0x0000, 0x7fff, MRA_ROM },
  134.     { 0x8000, 0x87ff, MRA_RAM },
  135.     { 0xa000, 0xa00d, K007232_read_port_0_r },
  136.     { 0xb000, 0xb00d, K007232_read_port_1_r },
  137.     { 0xc000, 0xc000, YM3812_status_port_0_r },
  138.     { 0xd000, 0xd000, soundlatch_r },
  139.     { -1 }    /* end of table */
  140. };
  141.  
  142. static struct MemoryWriteAddress spy_sound_writemem[] =
  143. {
  144.     { 0x0000, 0x7fff, MWA_ROM },
  145.     { 0x8000, 0x87ff, MWA_RAM },
  146.     { 0x9000, 0x9000, sound_bank_w },
  147.     { 0xa000, 0xa00d, K007232_write_port_0_w },
  148.     { 0xb000, 0xb00d, K007232_write_port_1_w },
  149.     { 0xc000, 0xc000, YM3812_control_port_0_w },
  150.     { 0xc001, 0xc001, YM3812_write_port_0_w },
  151.     { -1 }    /* end of table */
  152. };
  153.  
  154.  
  155.  
  156. INPUT_PORTS_START( spy )
  157.     PORT_START
  158.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
  159.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  160.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  161.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  162.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  163.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  164.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  165.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  166.  
  167.     PORT_START
  168.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START2 )
  169.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  170.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  171.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  172.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  173.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  174.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  175.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  176.  
  177.     PORT_START
  178.     PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) )
  179.     PORT_DIPSETTING(    0x02, DEF_STR( 4C_1C ) )
  180.     PORT_DIPSETTING(    0x05, DEF_STR( 3C_1C ) )
  181.     PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
  182.     PORT_DIPSETTING(    0x04, DEF_STR( 3C_2C ) )
  183.     PORT_DIPSETTING(    0x01, DEF_STR( 4C_3C ) )
  184.     PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ) )
  185.     PORT_DIPSETTING(    0x03, DEF_STR( 3C_4C ) )
  186.     PORT_DIPSETTING(    0x07, DEF_STR( 2C_3C ) )
  187.     PORT_DIPSETTING(    0x0e, DEF_STR( 1C_2C ) )
  188.     PORT_DIPSETTING(    0x06, DEF_STR( 2C_5C ) )
  189.     PORT_DIPSETTING(    0x0d, DEF_STR( 1C_3C ) )
  190.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ) )
  191.     PORT_DIPSETTING(    0x0b, DEF_STR( 1C_5C ) )
  192.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_6C ) )
  193.     PORT_DIPSETTING(    0x09, DEF_STR( 1C_7C ) )
  194.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  195.     PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) )
  196.     PORT_DIPSETTING(    0x20, DEF_STR( 4C_1C ) )
  197.     PORT_DIPSETTING(    0x50, DEF_STR( 3C_1C ) )
  198.     PORT_DIPSETTING(    0x80, DEF_STR( 2C_1C ) )
  199.     PORT_DIPSETTING(    0x40, DEF_STR( 3C_2C ) )
  200.     PORT_DIPSETTING(    0x10, DEF_STR( 4C_3C ) )
  201.     PORT_DIPSETTING(    0xf0, DEF_STR( 1C_1C ) )
  202.     PORT_DIPSETTING(    0x30, DEF_STR( 3C_4C ) )
  203.     PORT_DIPSETTING(    0x70, DEF_STR( 2C_3C ) )
  204.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_2C ) )
  205.     PORT_DIPSETTING(    0x60, DEF_STR( 2C_5C ) )
  206.     PORT_DIPSETTING(    0xd0, DEF_STR( 1C_3C ) )
  207.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )
  208.     PORT_DIPSETTING(    0xb0, DEF_STR( 1C_5C ) )
  209.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_6C ) )
  210.     PORT_DIPSETTING(    0x90, DEF_STR( 1C_7C ) )
  211. //    PORT_DIPSETTING(    0x00, "Invalid" )
  212.  
  213.     PORT_START
  214.     PORT_DIPNAME( 0x03, 0x02, DEF_STR( Lives ) )
  215.     PORT_DIPSETTING(    0x03, "2" )
  216.     PORT_DIPSETTING(    0x02, "3" )
  217.     PORT_DIPSETTING(    0x01, "5" )
  218.     PORT_DIPSETTING(    0x00, "7" )
  219.     PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
  220.     PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
  221.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  222.     PORT_DIPNAME( 0x18, 0x08, DEF_STR( Bonus_Life ) )
  223.     PORT_DIPSETTING(    0x18, "10k and every 20k" )
  224.     PORT_DIPSETTING(    0x10, "20k and every 30k" )
  225.     PORT_DIPSETTING(    0x08, "20k" )
  226.     PORT_DIPSETTING(    0x00, "30k" )
  227.     PORT_DIPNAME( 0x60, 0x40, DEF_STR( Difficulty ) )
  228.     PORT_DIPSETTING(    0x60, "Easy" )
  229.     PORT_DIPSETTING(    0x40, "Normal" )
  230.     PORT_DIPSETTING(    0x20, "Difficult" )
  231.     PORT_DIPSETTING(    0x00, "Very Difficult" )
  232.     PORT_DIPNAME( 0x80, 0x00, DEF_STR( Demo_Sounds ) )
  233.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  234.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  235.  
  236.     PORT_START
  237.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  238.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  239.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 )
  240.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
  241.     PORT_DIPNAME( 0x10, 0x10, DEF_STR( Flip_Screen ) )
  242.     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
  243.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  244.     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
  245.     PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
  246.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  247.     PORT_SERVICE( 0x40, IP_ACTIVE_LOW )
  248.     PORT_DIPNAME( 0x80, 0x80, "Continues" )
  249.     PORT_DIPSETTING(    0x80, "Unlimited" )
  250.     PORT_DIPSETTING(    0x00, "5 Times" )
  251. INPUT_PORTS_END
  252.  
  253.  
  254.  
  255. static void volume_callback0(int v)
  256. {
  257.     K007232_set_volume(0,0,(v >> 4) * 0x11,0);
  258.     K007232_set_volume(0,1,0,(v & 0x0f) * 0x11);
  259. }
  260.  
  261. static void volume_callback1(int v)
  262. {
  263.     K007232_set_volume(1,0,(v >> 4) * 0x11,0);
  264.     K007232_set_volume(1,1,0,(v & 0x0f) * 0x11);
  265. }
  266.  
  267. static struct K007232_interface k007232_interface =
  268. {
  269.     2,            /* number of chips */
  270.     { REGION_SOUND1, REGION_SOUND2 },    /* memory regions */
  271.     { K007232_VOL(40,MIXER_PAN_CENTER,40,MIXER_PAN_CENTER),
  272.             K007232_VOL(40,MIXER_PAN_CENTER,40,MIXER_PAN_CENTER) },    /* volume */
  273.     { volume_callback0, volume_callback1 }    /* external port callback */
  274. };
  275.  
  276.  
  277. static void irqhandler(int linestate)
  278. {
  279.     cpu_set_nmi_line(1,linestate);
  280. }
  281.  
  282. static struct YM3812interface ym3812_interface =
  283. {
  284.     1,            /* 1 chip */
  285.     3579545,    /* ??? */
  286.     { 100 },    /* volume */
  287.     { irqhandler },
  288. };
  289.  
  290.  
  291.  
  292. static struct MachineDriver machine_driver_spy =
  293. {
  294.     {
  295.         {
  296.             CPU_HD6309,
  297.             3000000, /* ? */
  298.             spy_readmem,spy_writemem,0,0,
  299.             spy_interrupt,2
  300.         },
  301.         {
  302.             CPU_Z80 | CPU_AUDIO_CPU,
  303.             3579545,
  304.             spy_sound_readmem, spy_sound_writemem,0,0,
  305.             ignore_interrupt,0    /* irq is triggered by the main CPU */
  306.                                 /* nmi by the sound chip */
  307.         }
  308.     },
  309.     60, DEFAULT_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  310.     1,    /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  311.     0,
  312.  
  313.     /* video hardware */
  314.     64*8, 32*8, { 14*8, (64-14)*8-1, 2*8, 30*8-1 },
  315.     0,    /* gfx decoded by konamiic.c */
  316.     1024, 1024,
  317.     0,
  318.  
  319.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  320.     0,
  321.     spy_vh_start,
  322.     spy_vh_stop,
  323.     spy_vh_screenrefresh,
  324.  
  325.     /* sound hardware */
  326.     0,0,0,0,
  327.     {
  328.         {
  329.             SOUND_YM3812,
  330.             &ym3812_interface
  331.         },
  332.         {
  333.             SOUND_K007232,
  334.             &k007232_interface
  335.         }
  336.     }
  337. };
  338.  
  339.  
  340. /***************************************************************************
  341.  
  342.   Game ROMs
  343.  
  344. ***************************************************************************/
  345.  
  346. ROM_START( spy )
  347.     ROM_REGION( 0x28800, REGION_CPU1 ) /* code + banked roms + space for banked ram */
  348.     ROM_LOAD( "857m03.bin",   0x10000, 0x10000, 0x3bd87fa4 )
  349.     ROM_LOAD( "857m02.bin",   0x20000, 0x08000, 0x306cc659 )
  350.     ROM_CONTINUE(             0x08000, 0x08000 )
  351.  
  352.     ROM_REGION( 0x10000, REGION_CPU2 ) /* Z80 code */
  353.     ROM_LOAD( "857d01.bin",   0x0000, 0x8000, 0xaad4210f )
  354.  
  355.     ROM_REGION( 0x080000, REGION_GFX1 ) /* graphics ( dont dispose as the program can read them ) */
  356.     ROM_LOAD( "857b09.bin",   0x00000, 0x40000, 0xb8780966 )    /* characters */
  357.     ROM_LOAD( "857b08.bin",   0x40000, 0x40000, 0x3e4d8d50 )
  358.  
  359.     ROM_REGION( 0x100000, REGION_GFX2 ) /* graphics ( dont dispose as the program can read them ) */
  360.     ROM_LOAD( "857b06.bin",   0x00000, 0x80000, 0x7b515fb1 )    /* sprites */
  361.     ROM_LOAD( "857b05.bin",   0x80000, 0x80000, 0x27b0f73b )
  362.  
  363.     ROM_REGION( 0x0200, REGION_PROMS )
  364.     ROM_LOAD( "857a10.bin",   0x0000, 0x0100, 0x32758507 )    /* priority encoder (not used) */
  365.  
  366.     ROM_REGION( 0x40000, REGION_SOUND1 ) /* samples for 007232 #0 */
  367.     ROM_LOAD( "857b07.bin",   0x00000, 0x40000, 0xce3512d4 )
  368.  
  369.     ROM_REGION( 0x40000, REGION_SOUND2 ) /* samples for 007232 #1 */
  370.     ROM_LOAD( "857b04.bin",   0x00000, 0x40000, 0x20b83c13 )
  371. ROM_END
  372.  
  373.  
  374.  
  375. static void gfx_untangle(void)
  376. {
  377.     konami_rom_deinterleave_2(REGION_GFX1);
  378.     konami_rom_deinterleave_2(REGION_GFX2);
  379. }
  380.  
  381. static void init_spy(void)
  382. {
  383.     paletteram = &memory_region(REGION_CPU1)[0x28000];
  384.     gfx_untangle();
  385. }
  386.  
  387.  
  388.  
  389. GAMEX( 1989, spy, 0, spy, spy, spy, ROT0, "Konami", "S.P.Y. - Special Project Y (US)", GAME_NOT_WORKING )
  390.